
class BaseDataBean<T extends BaseJsonBean> extends BaseBean{

  T? data;

  BaseDataBean({code,message,this.data}):super(code: code, message: message);

  BaseDataBean.fromJson(Map<String, dynamic> json,Function(Map<String, dynamic>) create):super.fromJson(json){
      data=create(json["data"]??Map<String, dynamic>());
  }

  Map<String, dynamic> toJson() {
    var json = super.toJson();
    json['data'] = this.data?.toJson();
    return json;
  }
}
//用于 返回状态的
class BaseStateDataBean<T> extends BaseBean{

  T? data;

  BaseStateDataBean({code,message,this.data}):super(code: code, message: message);

  BaseStateDataBean.fromJson(Map<String, dynamic> json):super.fromJson(json){
    data=json["data"];
  }

  Map<String, dynamic> toJson() {
    var json = super.toJson();
    json['data'] = this.data;
    return json;
  }
}

class BaseToListBean<T extends BaseJsonBean> extends BaseBean{

  List<T>? data;

  get getData{
    return data??[];
  }

  BaseToListBean({code,message,this.data}):super(code: code, message: message);

  BaseToListBean.fromJson(Map<String, dynamic> json,Function(Map<String, dynamic>) itemCreate):super.fromJson(json){
    if (json['data'] != null) {
      data = [];
      json['data'].forEach((v) {
        data?.add(itemCreate(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    var json = super.toJson();
    if (this.data != null) {
      json['data'] = this.data?.map((v) => v.toJson()).toList();
    }
    return json;
  }
}

class BaseBean{
  int? code;
  String? message;

  BaseBean({this.code, this.message});

  BaseBean.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    message = json['message'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['code'] = this.code;
    data['message'] = this.message;
    return data;
  }
}

abstract class BaseJsonBean{
  Map<String, dynamic> toJson();
}

class EmptyJsonBean extends BaseJsonBean{
  @override
  Map<String, dynamic> toJson() {
     return Map<String, dynamic>();
  }

  EmptyJsonBean.fromJson(Map<String, dynamic> json) {
  }
}